package com.zui.entity.product;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import com.zui.entity.BaseAutoIdEntity;
import com.zui.entity.setup.Uom;

@Entity
@Table(name = "product_content", uniqueConstraints = { @UniqueConstraint(name = "uc_product_content", columnNames = {
		"productId","productContentTypeId","fromDate" }) })
public class ProductContent extends BaseAutoIdEntity {
	private static final long serialVersionUID = 1L;
	private static final String THUMB_IMAGE_SUFFIX = "_thumb";
	private static final String MEDIUM_IMAGE_SUFFIX = "_medium";
	
	public static final String IMAGE_REAL_PATH 
		= System.getProperty("file.separator") 
		+ "upload" 
		+ System.getProperty("file.separator") 
		+ "images";
	
	
	public ProductContent(File originalImageFile) {
		this.originalImageFile = originalImageFile;
		this.fileName = originalImageFile.getName();
		this.directory = originalImageFile.getParent();
		this.fromDate = Calendar.getInstance().getTime();

		this.thumbFileName = fileName.substring(0, fileName.lastIndexOf("."))
				+ THUMB_IMAGE_SUFFIX
				+ fileName.substring(fileName.lastIndexOf("."));
		this.mediumFileName = fileName.substring(0, fileName.lastIndexOf("."))
				+ MEDIUM_IMAGE_SUFFIX
				+ fileName.substring(fileName.lastIndexOf("."));
	}

	private Product product;
	private ProductContentType productContentType;
	private Date fromDate;
	private Date thruDate;
	private Date purchaseFromDate;
	private Date purchaseThruDate;
	private Integer sequenceNum;
	private Long useCountLimit;
	private Long useTime;
	private Uom useTimeUom;
	
	private File originalImageFile;
	private String directory;
	private String fileName;
	private String thumbFileName;
	private String mediumFileName;

	/*------------------------------
	 * getters and annotations
	 --------------------------------*/
	@ManyToOne()
	@JoinColumn(name = "productId")
	public Product getProduct() {
		return product;
	}

	public String getFileName() {
		return fileName;
	}

	public String getDirectory() {
		return directory;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public Date getThruDate() {
		return thruDate;
	}

	public Integer getSequenceNum() {
		return sequenceNum;
	}

	@Transient
	public File getOriginalImageFile() {
		return originalImageFile;
	}

	public String getThumbFileName() {
		return thumbFileName;
	}

	public String getMediumFileName() {
		return mediumFileName;
	}
	@ManyToOne @JoinColumn(name = "productContentTypeId")
	public ProductContentType getProductContentType() {
		return productContentType;
	}

	public Date getPurchaseFromDate() {
		return purchaseFromDate;
	}

	public Date getPurchaseThruDate() {
		return purchaseThruDate;
	}

	public Long getUseCountLimit() {
		return useCountLimit;
	}

	public Long getUseTime() {
		return useTime;
	}
	
	@ManyToOne @JoinColumn(name = "timeUomId")
	public Uom getUseTimeUom() {
		return useTimeUom;
	}

	public void setProductContentType(ProductContentType productContentType) {
		this.productContentType = productContentType;
	}

	public void setPurchaseFromDate(Date purchaseFromDate) {
		this.purchaseFromDate = purchaseFromDate;
	}

	public void setPurchaseThruDate(Date purchaseThruDate) {
		this.purchaseThruDate = purchaseThruDate;
	}

	public void setUseCountLimit(Long useCountLimit) {
		this.useCountLimit = useCountLimit;
	}

	public void setUseTime(Long useTime) {
		this.useTime = useTime;
	}

	public void setUseTimeUom(Uom useTimeUom) {
		this.useTimeUom = useTimeUom;
	}

	public void setThumbFileName(String thumbFileName) {
		this.thumbFileName = thumbFileName;
	}

	public void setMediumFileName(String mediumFileName) {
		this.mediumFileName = mediumFileName;
	}

	public void setOriginalImageFile(File originalImageFile) {
		this.originalImageFile = originalImageFile;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}

	public void setThruDate(Date thruDate) {
		this.thruDate = thruDate;
	}

	public void setSequenceNum(Integer sequenceNum) {
		this.sequenceNum = sequenceNum;
	}
}
